/****************************************
* James Gomez                           *
* Project 3: Target Practice P3         *
* Comp 465                              *
* Professor Barnes                      *
* 12/7/2012                             *
*****************************************/

#ifndef _EXPLODABLE_
#define _EXPLODABLE_

#include "GomezJamesP3_OpenGL.h"


class Explodable{

protected:
	bool isActive, isExploding;
	int endRadius, currentRadius, growthRate;

public:
	Explodable();
	Explodable(int startRadius, int endRadius, int growthRate);
	~Explodable(){}

	inline bool active() const{ if(isActive) return true; return false; }
	inline bool exploding() const{ if(isExploding) return true; return false; }
	void setExploding(const bool flag){ isExploding = flag; }

	/* Explodable objects may choose to override these two methods */
	virtual void explode();
	virtual void drawExplosion(GLfloat *);

};

Explodable::Explodable(){
	 isActive = true; 
	 isExploding = false;	
	 currentRadius = 10;
	 endRadius = 240;
	 growthRate = 20;
}

Explodable::Explodable(int startRadius, int endRadius, int growthRate){
	isActive = true; 
	isExploding = false;	
	currentRadius = startRadius;
	this->endRadius = endRadius;
	this->growthRate = growthRate;
}

void Explodable::explode(){
	//animate explosion
	if (isActive){
		currentRadius += growthRate;

		if (currentRadius >= endRadius)
			isActive = false;
	}		
}

void Explodable::drawExplosion(GLfloat * tm){
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();	
	glMultMatrixf(tm);
	glColor3fv(orange);
	glutWireSphere(currentRadius, 20, 20);
	glPopMatrix();
}

#endif